<template>
	<view>
		<view class='integral-details'>
			<view class='wrapper'>
				<view class='nav acea-row'>
					<view class='item acea-row row-center-wrapper' :class='current==index?"on":""' v-for="(item,index) in navList" :key='index'
					 @click='nav(index)'><text class='iconfont' :class="item.icon"></text>{{item.name}}</view>
				</view>
				
				<view class='list' :hidden='current != 0' >
					<!-- <view class='item acea-row row-between-wrapper' v-for="(item,index) in upgradeList" :key="index">
						<view>
							<view class='state'>{{item.mark}}</view>
							<view>{{item.create_time}}</view>
						</view>
						<view class='num font-color' v-if="item.pm">+{{item.number}}</view>
						<view class='num' v-else>-{{item.number}}</view>
					</view> -->
					
					<view>
						<radio-group name="receipt_title_type" @change="changeHeader(item,index)"  v-for="(item,index) in upgradeList" :key="index" :class="checkList.meal_id == item.meal_id? 'active' : ''">
							
							<view class="acea-row row-middle choose">
							<label style="width: 100%;">
								<text>${{item.price}}</text>
								<text> {{item.name}}</text>
								<radio :value="item.meal_id" :checked="checkList.meal_id == item.meal_id? true : false" style="display: none;"/>
							</label>
							</view>
						</radio-group>
					</view>
					
					
					<view v-if="upgradeList.length == 0">
						<emptyPage :title="$t('yingxiao9')"></emptyPage>
					</view>
					
					<view v-if="checkList" class="ivu-text-left mb20">
						<view class="tips-box"  style="width: 100%;">
							<view class="tips mt-30" style="width: 100%;">{{$t('payMoney')}}：${{checkList.price}}</view>
							<view class="tips mt-30" style="width: 100%;">{{$t('payType')}}：{{$t('moneyPay')}}</view>
						</view>
						
						<button class='but' @click="nowpay"> {{$t('confirm.the.payment')}}</button>
					</view>
			
				</view>
				
				<view v-if="integral_status" class='list' :hidden='current!=1'>
					<view class='item acea-row row-between-wrapper' v-for="(item,index) in recordList" :key="index">
						<view>
							<view class='state'>{{item.order_info.name}}</view>
							<view>{{item.create_time}}</view>
						</view>
						<view class='num'>${{item.pay_price}}</view>
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="recordList.length>0">
						<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
					</view> 
					<view v-if="recordList.length == 0">
						<emptyPage title="There is no record yet～"></emptyPage>
					</view>
				</view>
			</view>
		</view>
		<view class="instructions" v-if="showProtocol">
			<view class="setAgCount">
				<i class="icon iconfont icon-cha" @click="showProtocol = false"></i>
				<div class="title">{{$t('Integral.description')}}</div>
				<view class="content">
					<jyf-parser :html="protocol" ref="article" :tag-style="tagStyle"></jyf-parser>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企業发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB並不是自由软件，未经许可不能去掉CRMEB相關版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import { getIntegralInfo, getpaylst2List,getupgradeList, YuePayApi2 } from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import emptyPage from '@/components/emptyPage.vue';
	import parser from "@/components/jyf-parser/jyf-parser";
	const app = getApp();
	export default {
		components: {
			// #ifdef MP
			authorize,
			// #endif
			emptyPage,
			"jyf-parser": parser,
		},
		data() {
			return {
				mer_id: '',
				navList: [{
						'name': this.$t("yingxiao2"),
					},
					{
						'name': this.$t("yingxiao7"),
					}
				],
				current: 0,
				page: 1,
				limit: 10,
				recordList: [],
				upgradeList:[],
				checkList: {},
				userInfo:{},
				loadend: false,
				loading: false,
				loadTitle: 'Load more',
				showProtocol: false,
				protocol: '',
				tagStyle: {
					img: 'width:100%;display:block;',
					video: 'width:100%;'
				},
				integral_status: true,
				isLogin:false,
			};
		},
		// computed: mapGetters(['isLogin']),
		onLoad(options) {
			this.mer_id = options.mer_id
			this.isLogin = this.$store.getters.isLogin()
			if (this.isLogin) {
				this.getUserInfo();							
			} else {
				// #ifdef H5 || APP-PLUS
				toLogin();
				// #endif 
			}
			this.getupgradeList();
		},
		
		/**
		   * 頁面上拉触底事件的处理函数
		   */
		  onReachBottom: function () {
		    this.getpaylst2List();
		  },
		methods: {
			/**
			 * 授权回调
			 */
			onLoadFun: function() {
				this.getUserInfo();							
			},
			// 授权關闭
			authColse: function(e) {
			},
			getUserInfo: function() {
				let that = this;
				getIntegralInfo().then(function(res) {
					that.$set(that,'userInfo',res.data);
					that.getpaylst2List()
				}).catch(res => {
					this.integral_status = false
					return that.$util.Tips({
						title: res
					});
				});
			},
			/**
			 * 获取购买明细
			 */
			getpaylst2List: function() {
				let that = this;
				if (that.loading) return;
				if (that.loadend) return;
				that.loading = true;
				that.loadTitle = '';
				getpaylst2List({
					type: 1,
					mer_id: this.mer_id,
					page: that.page,
					limit: that.limit
				}).then(function(res) {
					let list = res.data.list,
						loadend = list.length < that.limit;
					that.recordList = that.$util.SplitArray(list, that.recordList);
					that.$set(that,'recordList',that.recordList);
					that.page = that.page + 1;
					that.loading = false;
					that.loadend = loadend;
					that.loadTitle = loadend ? 'No more~' : "Load more";
				}, function(res) {
					this.loading = false;
					that.loadTitle = 'Load more';
				});
			},
			getupgradeList(){
				let that = this;
				that.loadTitle = '';
				getupgradeList({
					type: 'copy',
					page: 1,
					limit: 100
				}).then(function(res) {
					let list = res.data.list,
						loadend = list.length < that.limit;
					that.upgradeList = that.$util.SplitArray(list, that.upgradeList);
					that.checkList = that.upgradeList[0];
					that.$set(that,'upgradeList',that.upgradeList);
				}, function(res) {
				});
			},
			changeHeader(item, index) {
				this.checkList = item;
			},
			nav: function(current) {
				this.current = current;
			},
			//余额支付
			nowpay() {
			  const data = {
				pay_type: 1,
				mer_id: this.mer_id,
				meal_id: this.checkList.meal_id,
			  };
			  YuePayApi2(data)
				.then(res => {
					if(res.status==200)this.getpaylst2List();
					this.$util.Tips({ title: res.message });
				})
				.catch(err => {
					return this.$util.Tips({ title: err});
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	page{
		background-color: #fff;
	}
	.but {
		color: #fff;
		font-size: 30rpx;
		width: 700rpx;
		height: 86rpx;
		border-radius: 50rpx;
		margin: 46rpx auto 0 auto;
		line-height: 86rpx;
		background-color: #1890ff;
		    border-color: #1890ff;
	}
	.choose{
		padding-left: 10px;
		padding-right: 10px;
		border: 1px solid #dadfe6;
		padding: 20px 10px;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		border-radius: 3px;
		text-align: center;
		position: relative;
		cursor: pointer;
		margin-bottom: 20rpx;
		text{
			display: block;
		}
	}
	.active{
		background: #0091ff;
		color: #fff!important;
	}
	.integral-details .wrapper .nav {
		flex: 1;
		border-radius: 20rpx 20rpx 0 0;
		margin:  auto 0 auto;
		background-color: #f7f7f7;
		height: 96rpx;
		font-size: 30rpx;
		color: #bbb;
	}

	.integral-details .wrapper .nav .item {
		text-align: center;
		width: 50%;
	}

	.integral-details .wrapper .nav .item.on {
		background-color: #fff;
		color: #e93323;
		font-weight: bold;
		border-radius: 20rpx 0 0 0;
	}

	.integral-details .wrapper .nav .item:nth-of-type(2).on {
		border-radius: 0 20rpx 0 0;
	}

	.integral-details .wrapper .nav .item .iconfont {
		font-size: 38rpx;
		margin-right: 10rpx;
	}

	.integral-details .wrapper .list {
		background-color: #fff;
		padding: 24rpx 30rpx;
	}

	.integral-details .wrapper .list .tip {
		font-size: 25rpx;
		width: 690rpx;
		border-radius: 50rpx;
		background-color: #fff5e2;
		border: 1rpx solid #ffeac1;
		color: #c8a86b;
		padding: 10rpx 20rpx 10rpx 55rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;
		position: relative;
	}
	.integral-details .wrapper .list .tip .iconfont {
		font-size: 35rpx;
		margin-right: 15rpx;
		position: absolute;
		top: 10rpx;
		left: 16rpx;
	}
	.integral-details .wrapper .list .item {
		height: 124rpx;
		border-bottom: 1rpx solid #eee;
		font-size: 24rpx;
		color: #999;
	}

	.integral-details .wrapper .list .item .state {
		font-size: 28rpx;
		color: #282828;
		margin-bottom: 8rpx;
	}

	.integral-details .wrapper .list .item .num {
		font-size: 36rpx;
	}

	.integral-details .wrapper .list2 {
		background-color: #fff;
		padding: 24rpx 0;
	}

	.integral-details .wrapper .list2 .item {
		background-image: linear-gradient(to right, #fff7e7 0%, #fffdf9 100%);
		width: 690rpx;
		height: 180rpx;
		position: relative;
		border-radius: 10rpx;
		margin: 0 auto 20rpx auto;
		padding: 0 25rpx 0 180rpx;
		box-sizing: border-box;
	}

	.integral-details .wrapper .list2 .item .pictrue {
		width: 90rpx;
		height: 150rpx;
		position: absolute;
		bottom: 0;
		left: 45rpx;
	}

	.integral-details .wrapper .list2 .item .pictrue image {
		width: 100%;
		height: 100%;
	}

	.integral-details .wrapper .list2 .item .name {
		width: 285rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #c8a86b;
	}

	.integral-details .wrapper .list2 .item .earn {
		font-size: 26rpx;
		color: #c8a86b;
		border: 2rpx solid #c8a86b;
		text-align: center;
		line-height: 52rpx;
		height: 52rpx;
		width: 160rpx;
		border-radius: 50rpx;
	}
	.instructions{
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, .5);
		z-index: 10;
	}
	.instructions .setAgCount {
		background: #fff;
		width: 656rpx;
		height: 458px;
		position: absolute;
		top: 50%;
		left: 50%;
		border-radius: 12rpx;
		-webkit-border-radius: 12rpx;
		padding: 52rpx;
		-webkit-transform: translate(-50%, -50%);
		-moz-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		overflow: hidden;	
		.content {
			height: 900rpx;
			overflow-y: scroll;	
			::v-deep p {
				font-size: 13px;
				line-height: 22px;
			}	
			::v-deep img {
				max-width: 100%;
			}
		}
	}	
	.instructions .setAgCount .icon {
		font-size: 42rpx;
		color: #b4b1b4;
		position: absolute;
		top: 15rpx;
		right: 15rpx;	
	}
	
	.instructions .setAgCount .title {
		color: #333;
		font-size: 32rpx;
		text-align: center;
		font-weight: bold;
	}	
	.instructions .setAgCount .content {
		margin-top: 32rpx;
		color: #333;
		font-size: 26rpx;
		line-height: 22px;
		text-align: justify;
		text-justify: distribute-all-lines;
		height: 756rpx;
		overflow-y: scroll;
	}
</style>
